package org.example.spring.repository.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.example.spring.repository.service.IClientService;
import org.example.spring.repository.service.IDepartmentService;
import org.example.spring.repository.service.IUserService;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * LuoYu
 * 2022/12/12 19:54
 **/
@Service
@Slf4j
@Primary
public class ClientServiceImpl implements IClientService {


    @Resource
    private IUserService userService;

    @Resource
    private IDepartmentService departmentService;


    @Override
    @Transactional(rollbackFor = Exception.class)
    public void required() {
        userService.createUserREQUIRED("王二",false);
        departmentService.createREQUIRED("353",true);
    }




    @Override
    public void supports() {
        departmentService.createSupports("sdjflsdfj",true);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void requiredWithSupport() {
        departmentService.createSupports("22222222",true);

    }

    @Override
    public void mandatory() {
        departmentService.createMandatory("345345345",true);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void requiredWitchMandatory() {
        departmentService.createMandatory("555566666",true);

    }

    @Override
    public void requiredNew() {
        departmentService.createRequiredNew("777778888",true);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void requiredWitchRequiredNew(boolean hasThrow) {
        departmentService.createRequiredNew("888884444",false);
        if(hasThrow) {
            System.out.println( 2 / 0);
        }
    }

    @Override
    public void never() {
        departmentService.createNever("69696969",true);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void requiredWithNever() {
        departmentService.createNever("69696969457547",true);
    }

    @Override
    public void nested() {
        departmentService.createNested("1234235423",true);
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public void requiredNested(boolean hasThrow) {
        departmentService.createNested("089gfhfdh",false);
        if(hasThrow) {
            System.out.println( 2 / 0);
        }
    }


}
